/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.generate;

import com.jl.tools.stkeditor.exception.DataNotMatchCodingScheamException;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public final class UCS2Code implements Code {

    private String mode = "80";
    private String oneline = "";

    public UCS2Code(String oneline, String mode) {
        this.oneline = oneline;
        this.mode = mode;
    }

    public UCS2Code(String oneline) {
        this.oneline = oneline;
    }

    @Override
    public List<String> getCode() throws DataNotMatchCodingScheamException {
        List<String> l = new ArrayList<String>();
        l.add(mode);
        for (int i = 0; i < oneline.length(); i++) {
            l.addAll(getOneCharCode(i));
        }
        return l;
    }

    @Override
    public int getLength() {
        return oneline.length() * 2 + 1;
    }

    private List<String> getOneCharCode(int i) {
        List<String> l = new ArrayList<String>();
        String temp = Integer.toHexString(oneline.codePointAt(i));
        while (temp.length() < 4) {
            temp = "0" + temp;
        }
        temp = temp.toUpperCase();
        l.add(temp.substring(0, 2));
        l.add(temp.substring(2));
        return l;
    }
}
